using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The DayGroupCodeTableManager class is responsible for managing BO.DayGroupCodeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class DayGroupCodeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all DayGroupCodeTable objects in the database.
        /// </summary>
        /// <returns>A list with all DayGroupCodeTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static DayGroupCodeTableList GetList()
        {
            return DayGroupCodeTableDB.GetList();
        }

        /// <summary>
        /// Gets a single DayGroupCodeTable from the database without its data.
        /// </summary>
        /// <param name="dayGroupCode">The DayGroupCode of the DayGroupCodeTable in the database.</param>
        /// <returns>A DayGroupCodeTable object when the DayGroupCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DayGroupCodeTable GetItem(short dayGroupCode)
        {
            return GetItem(dayGroupCode, false);
        }

        /// <summary>
        /// Gets a single DayGroupCodeTable from the database.
        /// </summary>
        /// <param name="dayGroupCode">The DayGroupCode of the DayGroupCodeTable in the database.</param>
        /// <param name="getDayGroupCodeTableRecords">Determines whether to load all associated DayGroupCodeTable records as well.</param>
        /// <returns>
        /// A DayGroupCodeTable object when the DayGroupCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static DayGroupCodeTable GetItem(short dayGroupCode, bool getDayGroupCodeTableRecords)
        {
            DayGroupCodeTable myDayGroupCodeTable = DayGroupCodeTableDB.GetItem(dayGroupCode);
            return myDayGroupCodeTable;
        }

        /// <summary>
        /// Saves a DayGroupCodeTable in the database.
        /// </summary>
        /// <param name="myDayGroupCodeTable">The DayGroupCodeTable instance to save.</param>
        /// <returns>The new DayGroupCode if the DayGroupCodeTable is new in the database or the existing DayGroupCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(DayGroupCodeTable myDayGroupCodeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short dayGroupCodeTableDayGroupCode = DayGroupCodeTableDB.Save(myDayGroupCodeTable);

                //  Assign the DayGroupCodeTable its new (or existing DayGroupCode).
                myDayGroupCodeTable.DayGroupCode = dayGroupCodeTableDayGroupCode;

                myTransactionScope.Complete();

                return dayGroupCodeTableDayGroupCode;
            }
        }

        /// <summary>
        /// Deletes a DayGroupCodeTable from the database.
        /// </summary>
        /// <param name="myDayGroupCodeTable">The DayGroupCodeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(DayGroupCodeTable myDayGroupCodeTable)
        {
            return DayGroupCodeTableDB.Delete(myDayGroupCodeTable.DayGroupCode);
        }

        public static bool Delete(short DayGroupCode)
        {
            return DayGroupCodeTableDB.Delete(DayGroupCode);
        }

        #endregion

    }

}
